package de.kieselbach.javafx.builder.factory

import javafx.scene.image.ImageView

import javafx.scene.control.Label

/*
 * Copyright 2012 by procar informatik AG,
 * Eschenweg 7, 64331 Weiterstadt, Germany
 * All rights reserved.
 */
class LabelBuilderFactory extends AbstractBuilderFactory {

    @Override
    String getName() {

        return 'label'
    }

    @Override
    Class getNodeClass() {

        return Label.class
    }

    @Override
    void nodeCompleted(Object parent, Object child) {

        throw new UnsupportedOperationException("You cannot add child nodes to a button!");
    }

    @Override
    def createNode(Object name, Map attributes, Object value) {

        def label = new Label()

        if(value) {
            label.text = value
        }

        if(attributes != null) {
            attributes.each() {key, val ->
                if(key == 'image') {
                    if(val) {
                        label.graphic = new ImageView(val)
                    }
                }
                else {
                    label[key] = val
                }
            }
        }

        label
    }
}
